home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / E / PlayTHX / src / PlayTHX_gui.e < prev    next >
Encoding:
Text File  |  1997-10-07  |  2.8 KB  |  120 lines

  1. OPT OSVERSION=37
  2.  
  3. MODULE    'asl', 'libraries/asl', 'tools/EasyGUI_lite', 'tools/file',
  4.     'tools/thx-play', 'utility/tagitem'
  5.  
  6. DEF mod=NIL,len,stopped=FALSE,song=0
  7.  
  8. PROC main() HANDLE
  9.   easyguiA('PlayTHX',
  10.     [ROWS,
  11.       [EQCOLS,
  12.         [SBUTTON,{psub}, '|<',   0,0],
  13.         [SBUTTON,{rew},  '<<',   0,0],
  14.         [SBUTTON,{play}, 'Play', 0,0],
  15.         [SBUTTON,{ffwd}, '>>',   0,0],
  16.         [SBUTTON,{nsub}, '>|',   0,0]
  17.       ],
  18.       [EQCOLS,
  19.         [SBUTTON,{stop}, 'Stop',    0,0],
  20.         [SBUTTON,{eject},'Eject',   0,0],
  21.         [SBUTTON,{open}, 'Open...', 0,0]
  22.       ]
  23.     ],0
  24.   )
  25.   Raise()    
  26. EXCEPT
  27.   eject()   -> free module (if loaded)
  28.   thxFree() -> free player
  29. ENDPROC
  30.  
  31. PROC rew() IS IF mod THEN thxWind(-1) ELSE 0
  32. PROC ffwd() IS IF mod THEN thxWind(1) ELSE 0
  33.  
  34. PROC psub()
  35.   stop()
  36.   IF song>0 THEN thxSetSong(song:=song-1)
  37.   play()
  38. ENDPROC
  39.  
  40. PROC nsub()
  41.   stop()
  42.   IF song<thxGetNumSongs() THEN thxSetSong(song:=song+1)
  43.   play()
  44. ENDPROC
  45.  
  46.  
  47. PROC stop()
  48.   IF mod=NIL THEN RETURN
  49.   thxStop()
  50.   stopped:=TRUE  -> mark as stopped
  51. ENDPROC
  52.  
  53. PROC eject()
  54.   IF mod=NIL THEN RETURN
  55.   stop()
  56.   freefile(mod)  -> free module
  57.   mod:=NIL       -> mark as freed
  58. ENDPROC
  59.   
  60. PROC play()
  61.   IF mod=NIL THEN RETURN
  62.  
  63.   IF stopped
  64.     thxSetVolume(64)
  65.     thxPlay()        -> start playing
  66.     stopped:=FALSE   -> no longer stopped
  67.   ELSE
  68.     -> if playing (not stopped)
  69.     thxSetVolume(0)
  70.     Delay(2)        -> dirty kludge (setvolume needs 'a while' to happen)
  71.     thxPause()       -> pause
  72.     stopped:=TRUE    -> paused is ~same as stopped :)
  73.   ENDIF
  74. ENDPROC
  75.  
  76. PROC open() HANDLE
  77.   DEF file
  78.   IF (file:=asl_req())=0 THEN RETURN -> return if no file selected
  79.  
  80.   eject()  -> eject current module
  81.  
  82.   mod,len:=readfile(file)  -> read new module
  83.   DisposeLink(file) -> free memory of 'file' string (pedantic)
  84.  
  85.   IF mod=NIL THEN Raise(1)         -> no mod loaded? give up
  86.   IF thxInit(mod)<>0 THEN Raise(1) -> thxInit() failed? give up
  87.  
  88.   song:=0
  89.   stopped:=TRUE
  90.   play()
  91.  
  92. EXCEPT
  93.   IF exception THEN eject()
  94. ENDPROC
  95.  
  96.  
  97. ->----- an asl requester
  98.  
  99. PROC asl_req(title=NIL,dir=NIL,save=FALSE)
  100.   DEF req:PTR TO filerequester, file=NIL, tail=0
  101.   IF aslbase=NIL THEN aslbase:=OpenLibrary('asl.library',37)
  102.   IF aslbase=NIL THEN RETURN NIL
  103.  
  104.   IF req:=AllocAslRequest(ASL_FILEREQUEST,0)
  105.     IF AslRequest(req,[ASLFR_INITIALDRAWER,dir,
  106.                        ASLFR_TITLETEXT,IF title THEN title ELSE 'Select file...',
  107.                        ASLFR_FLAGS1,IF save THEN FRF_DOSAVEMODE ELSE 0,
  108.                        TAG_DONE
  109.                       ])
  110.       IF file:=String(StrLen(req.drawer)+StrLen(req.file)+1)
  111.         StrCopy(file,req.drawer)
  112.         IF StrLen(req.drawer) THEN tail:=Char(req.drawer+StrLen(req.drawer)-1)
  113.         IF (tail<>":") AND (tail<>"/") AND (tail<>0) THEN StrAdd(file,'/')
  114.         StrAdd(file,req.file)
  115.       ENDIF
  116.     ENDIF
  117.     FreeAslRequest(req)
  118.   ENDIF
  119. ENDPROC file
  120.